<?php
include("../common.inc.php");
InitGP(array("page","action","sid","delids")); //初始化变量全局返回
include("function_common.php");
//初始化对象
include(INC_PATH."/suppliers.class.php");
$sp=new SupplierClass();

if(empty($action)){
	InitGP(array("name")); //初始化变量全局返回
	if(!empty($name))$wherestr[]="name like '%{$name}%'";
	if(!empty($wherestr)) $wheresql = implode(' AND ', $wherestr);	//条件汇总
	//获取当前页码
	$total=$sp->getcount($wheresql); 							  //总信息数
	$pagesize=15;												  //一页显示信息数
	$page = isset($page) ? max(1, intval($page)) : 1;             //处理页码变量
	$offset=($page-1)*$pagesize;   								  //偏移量
	$dataarray=$sp->getdata("$offset,$pagesize",$wheresql); //获取团购数据
	
	//包含后台模板文件
	include("tpl/suppliers_list.htm");	
}elseif ($action=="edit") {
	InitGP(array("sid","name","web","img","imgold","address","map","tel","operating_time","resolution","codebar","bus","brief","about","pwd","Submit")); //初始化变量全局返回
	if(!empty($Submit)){
		//处理提交动作
		if(isset($sid) && isset($name)){
		//处理数据
		$sid=GetNum($sid);
		//上传图片处理
		require_once (INC_PATH.'/upload.class.php');
		$f = new Upload();
		$f->setThumb(0);//设置不生成缩微图
		$f->run('fileimg',1);
		$info=$f->getInfo();
		$imgdata=$info[0]['fullsavename'];//获取第一个上传图片反馈
		if(isset($info[0]['error']))$imgdata=$imgold;
			
		$arrayedit=array(
		"name"=>Char_cv($name),
		"web"=> $web,
		"img"=>$imgdata,
		"address"=>Char_cv($address),
		"map"=>Char_cv($map),
		"tel"=>Char_cv($tel),
		"operating_time"=>Char_cv($operating_time),
		"resolution"=>Char_cv($resolution),
		"codebar"=>Char_cv($codebar),
		"bus"=>Char_cv($bus),
		"brief"=>Char_cv($brief),
		"about"=>$about,
		"pwd"=>$pwd
		);
		//执行编辑操作
		$info=$sp->edit($sid,$arrayedit);
			if($info=="OK"){
				showmsg("编辑商家信息成功!","suppliers_list.php");//成功
			}else showmsg($info,"suppliers_add.php");//出错！
		}else showmsg("缺少参数","suppliers_add.php");//出错！
	}else {
		//编辑信息表单
		$dataedit=$sp->getdata(1,"sid={$sid}");
		$value=$dataedit[0];//获取第一条记录
		//包含后台模板文件
		include("tpl/suppliers_edit.htm");	
	}
	
}elseif ($action=="del" && !empty($sid)){
	//执行删除操作放入回收站
	$sid=GetNum($sid);
	$info=$sp->del($sid);
	if($info=="OK")showmsg("删除商家成功！","suppliers_list.php");
	else showmsg($info,"suppliers_list.php");
}elseif ($action=="dels"){
	if(empty($delids)){showmsg("没有选择任何对象！","suppliers_list.php");exit;}//空选择
	//执行删除多个操作
	foreach ($delids as $id){
		$id=GetNum($id);
		$info=$sp->del($id);
	}
	if($info=="OK")showmsg("删除商家成功！","suppliers_list.php");
	else showmsg($info,"suppliers_list.php");
}

?>

